package com.jkc.xh.adapters.viewholder;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jkc.xh.R;
import com.jkc.xh.models.HoldOneModel;

import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by wangjie28 on 2015/11/13.
 */
@EViewGroup(R.layout.item_sold_part)
public class SoldPartItemView extends RelativeLayout {

    @ViewById(R.id.optionLayout)
    View optionLayout;
    @ViewById(R.id.dataLayout)
    View dataLayout;
    @ViewById
    TextView stock_name;
    @ViewById
    TextView market_value;
    @ViewById
    TextView profit_money;
    @ViewById
    TextView profit_rate;
    @ViewById
    TextView own_amount;
    @ViewById
    TextView enable_amount;
    @ViewById
    TextView last_price;
    @ViewById
    TextView stop_price;

    public SoldPartItemView(Context context) {
        super(context);
    }

    public SoldPartItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }


    public void bind(HoldOneModel model) {
        stock_name.setText(model.stock_name);
        stop_price.setText(model.stop_price);
        own_amount.setText(model.own_amount);
        enable_amount.setText(model.enable_amount);
        last_price.setText(model.last_price);
        market_value.setText(model.market_value);
        profit_money.setText(model.profit_money);
        profit_rate.setText(model.profit_rate);

        if (model.isProfit()) {
            setAllTextColor(getResources().getColor(R.color.text_color_red));
        } else {
            setAllTextColor(getResources().getColor(R.color.text_color_blue));
        }
        if (model.isStop()) {
            setAllTextColor(getResources().getColor(R.color.text_color_gray));
        }
    }

    public void showMoreOption() {
        optionLayout.setVisibility(View.VISIBLE);
    }

    public void disableMoreOption() {
        optionLayout.setVisibility(View.GONE);
//        dataLayout.setBackgroundColor(R.color);
    }

    private void setAllTextColor(int textColorId) {
        stock_name.setTextColor(textColorId);
        own_amount.setTextColor(textColorId);
        enable_amount.setTextColor(textColorId);
        last_price.setTextColor(textColorId);
        market_value.setTextColor(textColorId);
        profit_money.setTextColor(textColorId);
        profit_rate.setTextColor(textColorId);
        stop_price.setTextColor(textColorId);
    }

}
